/**************************************************************************
	Replication do-file: "Corruption in Customs"
	Cyril Chalendard, Ana Fernandes, Gael Raballand and Bob Rijkers
	
	Created on: 01/07/2022
**************************************************************************/

clear all
set more off, perm
cap log close
cls

* Extra commands: remove the asterisk to install
*net install cleanplots, from("https://tdmize.github.io/data/cleanplots")
*set scheme cleanplots, perm

* ----------------------- DIRECTORIES AND FOLDERS ----------------------- *

* Directories in which data are stored
global main "PUT YOUR DIRECTORY PATH HERE"
cd "$folder"

* Folders
global outputdata = "$main\Output Data"
cap mkdir "$main\Figures"
global figures = "$main\Figures"

* ----------------------------- BEGINS HERE ----------------------------- *

* -------
* Dataset
* -------
use "$outputdata\CFRR.dta", clear // open dataset


* --------
* Figure 4
* --------

* Panel A: risk score
* -------------------
preserve
drop if eis_f>0.25
twoway lpolyci risk eis_f if sample_reg==1 & eis_f<0.25, ///
	clpattern(solid) clw(medthin) clcolor(gs5) ///
	fcolor(gs10) fi(inten40) alcol(gs10) alw(thin) ///
	xlabel(, nogrid) ///
	ylabel(, angle(0) labsize(small) nogrid) ///
	ytitle("Risk score", size(small) color(black)) ///
	xtitle("Excess interaction share", size(small) color(black)) ///
	legend(pos(6) ring(10) col(2) label(1 "95% CI") label(2 "Fitted")) ///
	name(Figure_4a, replace)
graph export "$figures\Figure_4a.eps", as(eps) replace
graph export "$figures\Figure_4a.pdf", as(pdf) replace
restore

* Panel B: tax rate
* ------------------
twoway lpolyci tax_rate eis_f if sample_reg==1 & eis_f<0.25, ///
	clpattern(solid) clw(medthin) clcolor(gs5) ///
	fcolor(gs10) fi(inten40) alcol(gs10) alw(thin) ///
	xlabel(, nogrid) ///
	ylabel(, angle(0) labsize(small) nogrid) ///
	ytitle("Tax rate", size(small) color(black)) ///
	xtitle("Excess interaction share", size(small) color(black)) ///
	legend(pos(6) ring(10) col(2) label(1 "95% CI") label(2 "fitted")) ///
	name(Figure_4b, replace)
graph export "$figures\Figure_4b.eps", as(eps) replace
graph export "$figures\Figure_4b.pdf", as(pdf) replace

* Panel C: unit price
* -------------------
twoway lpolyci nup_gap_i_int eis_f if sample_reg==1 & eis_f<0.25, ///
	clpattern(solid) clw(medthin) clcolor(gs5) ///
	fcolor(gs10) fi(inten40) alcol(gs10) alw(thin) ///
	xlabel(, nogrid) ///
	ylabel(, angle(0) labsize(small) nogrid) ///
	ytitle("Log (unit price/median unit price)", size(small) color(black)) ///
	xtitle("Excess interaction share", size(small) color(black)) ///
	legend(pos(6) ring(10) col(2) label(1 "95% CI") label(2 "fitted")) ///
	name(Figure_4c, replace)
graph export "$figures\Figure_4c.eps", as(eps) replace
graph export "$figures\Figure_4c.pdf", as(pdf) replace

* Panel D: initial revenue loss
* -----------------------------
twoway lpolyci htrl_i_int eis_f if sample_reg==1 & eis_f<0.25, ///
	clpattern(solid) clw(medthin) clcolor(gs5) ///
	fcolor(gs10) fi(inten40) alcol(gs10) alw(thin) ///
	xlabel(, nogrid) ///
	ylabel(, angle(0) labsize(small) nogrid) ///
	ytitle("Log potential revenue loss", size(small) color(black)) ///
	xtitle("Excess interaction share", size(small) color(black)) ///
	legend(pos(6) ring(10) col(2) label(1 "95% CI") label(2 "fitted")) ///
	name(Figure_4d, replace)
graph export "$figures\Figure_4d.eps", as(eps) replace
graph export "$figures\Figure_4d.pdf", as(pdf) replace

* Panel E: high potential tax yield
* ---------------------------------
twoway lpolyci e20 eis_f if sample_ext==1 & eis_f<0.25, ///
	clpattern(solid) clw(medthin) clcolor(gs5) ///
	fcolor(gs10) fi(inten40) alcol(gs10) alw(thin) ///
	xlabel(, nogrid) ///
	ylabel(, angle(0) labsize(small) nogrid) ///
	ytitle("High potential yield declaration (probability)", size(small) color(black)) ///
	xtitle("Excess interaction share", size(small) color(black)) ///
	legend(pos(6) ring(10) col(2) label(1 "95% CI") label(2 "fitted")) ///
	name(Figure_4e, replace)
graph export "$figures\Figure_4e.eps", as(eps) replace
graph export "$figures\Figure_4e.pdf", as(pdf) replace


* -------------------------------- ENDS HERE -------------------------------- *